import { HTTP } from 'utils/http';
import config from 'utils/config';

// 添加用户
class AddUserModel extends HTTP {
    addUser(userTel, userPwd) {
        return new Promise((resolve, reject) => {
            this.axiosPost({
                url: config.API.ADD_USER,
                data: {
                    userTel,
                    userPwd
                },
                success(data) {
                    resolve({
                        data,
                        status: 0
                    });
                },
                error(error) {
                    resolve({
                        error,
                        status: -1
                    })
                }
            });

        });
    }
}

// 登录
class LoginModel extends HTTP {
    login(userTel, userPwd) {
        return new Promise((resolve, reject) => {
            this.axiosPost({
                url: config.API.LOGIN,
                data: {
                    userTel,
                    userPwd
                },
                success(data) {
                    resolve({
                        data,
                        status: 0
                    });
                },
                error(error) {
                    resolve({
                        error,
                        status: -1
                    })
                }
            });

        });
    }
}


// 修改密码
class UpdateUserPwdModel extends HTTP {
    updateUserPwd(pwd, id) {
        return new Promise((resolve, reject) => {
            this.axiosPost({
                url: config.API.UPDATE_USER_PWD,
                data: {
                    pwd,
                    id
                },
                success(data) {
                    resolve({
                        data,
                        status: 0
                    });
                },
                error(error) {
                    resolve({
                        error,
                        status: -1
                    })
                }
            });

        });
    }
}

export { AddUserModel, LoginModel, UpdateUserPwdModel };